import React, { Component } from 'react'
import { connect } from 'react-redux'
import { toggleDmShow } from '../../actions/dmAction'


class DmSwitch extends Component {
  clickSwitch = () => {
    const { show, dispatch } = this.props
    dispatch(toggleDmShow(!show))
  }
  render() {
    const { show } = this.props
    return (
      <div className={ show ? "dm_switch switch_on" : "dm_switch switch_off" } onClick={this.clickSwitch}>
        <div className="switch">{ show ? '开' : '关' }</div>
      </div>
    )
  }
}

const mapStateToProps = (state) => {
  return {
    show: state.DmState.show
  }
}

export default connect(mapStateToProps)(DmSwitch)
